package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.IllDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.Ill;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

@Service(interfaceClass = IllService.class)
@Transactional
public class IllServiceImpl implements IllService {
    @Autowired
    private IllDao illDao;
    //添加疾病库
    public void add(Ill ill) {
        illDao.add(ill);
    }

    //分页查询
    public PageResult findPage(QueryPageBean queryPageBean) {
        Integer pageSize = queryPageBean.getPageSize();
        Integer currentPage = queryPageBean.getCurrentPage();
        String queryString = queryPageBean.getQueryString();
        PageHelper.startPage(currentPage,pageSize);
        Page<Ill> page = illDao.findByCondition(queryString);
        return new PageResult(page.getTotal(),page.getResult());
    }

    //编辑
    public void edit(Ill ill) {
        illDao.edit(ill);
    }

    //按照id查询
    public Ill findById(Integer id) {
        return illDao.findById(id);
    }

    @Override
    public void delete(Integer id) {
        illDao.delete(id);
    }

}
